package com.dhy.payutil.wechat;

import java.security.MessageDigest;

public class MD5 {
	public static String digest(String input) {
		return digest(input.getBytes());
	}

	public static String digest(byte[] input) {
		try {
			MessageDigest instance = MessageDigest.getInstance("MD5");
			instance.update(input);
			byte[] md = instance.digest();
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < md.length; i++) {
				int val = md[i] & 0xff;
				sb.append(String.format("%02x", val));
			}
			return sb.toString();
		} catch (Exception e) {
			return "";
		}
	}
}
